<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/gsap.min.js"></script>

    <script src="https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/ScrollTrigger.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/gsap@3.13.0/dist/TextPlugin.min.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        body {
            /* display: flex;
            align-items: center;
            justify-content: stretch;
            min-height: 100vh; */
        }
        .box1 {
            height: 100vh;
            background-color: #eee;
            display: flex;
            align-items: center;
            justify-content: stretch;
        }
        #t1 {
          /* transform: translateX(-100%); */
          opacity: 0;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <div class="box1"></div>
        <div class="box1" style="background-color: azure;">
            <div style="padding-left: 15px;">
                <h1 id="t1">GreenSock's TextPlugin<span style="color: orange;"></span></h1>
                <h2 id="t2">Set or animate text in sequence. Reversible too!</h2>
            </div>
        </div>
        <div class="box1"></div>
        
        
      </div>

    <!-- <button id="animate">animate</button> -->
    <script>
        // use a script tag or an external JS file
        document.addEventListener("DOMContentLoaded", (event) => {
            gsap.registerPlugin(ScrollTrigger,TextPlugin)
            const t1 = document.getElementById("t1")
            // 创建一个补间动画
            // const tween = gsap
            gsap.fromTo(t1, 
                { autoAlpha: 0, xPercent: -100, duration: 1 },
                { autoAlpha: 1, xPercent: 0, duration: 1, color: 'purple', ease: 'Power4.easeInOut',
                    scrollTrigger: {
                        trigger: t1,
                        start: "top 80%",
                        end: "bottom 20%",
                        scrub: 0.5,
                        pin: false,
                        markers: true
                    }

                },
                // {
                //     scale: 1,
                //     x: 0,
                //     opacity: 1,
                //     color: 'purple',
                //     skew: 30,
                //     duration: 1,
                //     ease: 'Power4.easeInOut'
                // }, {
                //     repeat: 1,
                //     x: 10,
                //     yoyo: true,
                // }
            )
            // gsap.to(t1, {
            //     repeat: 1,
            //     x: 10,
            //     yoyo: true,
            // })
            const t2 = document.getElementById("t2")
            // 创建一个补间动画
            // const tween = gsap
            gsap.fromTo(t2, 
                { autoAlpha: 0, xPercent: -100, },
                { autoAlpha: 1, xPercent: 0, delay: 0.5, duration: 1, color: 'orange', ease: 'Power4.easeInOut',
                    scrollTrigger: {
                        trigger: t2,
                        start: "top 80%",
                        end: "bottom 20%",
                        scrub: 0.5,
                        pin: false,
                        markers: true
                    }
                },
            )
        });
       
       </script>
</body>
</html>